A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

Pascal Integers And Numbers And Etc



Here is a chart for easy reference and convenience:
IMPORTANT NOTE: Each compiler can be slightly different in how they have implemented integers and reals.
Delphi:
 INTEGER TYPE         VALID RANGE

 byte         :       0 to 255

 longint      :       -2147483648 to 2147483648

 shortint     :       -128 to 127

 smallint     :       -32768 to 32767

 word         :       0 to 65535


 REAL TYPE            VALID RANGE

 comp         :       (-2 power of 63) + 1 to (2 power of 63) - 1 

 currency     :       -922337203686477.5808 to 922337203685477.5807

 double       :       5.0 x (10 power of -324) to 1.7 x (10 power of 308)

 extended     :       3.4 x (10 power of -4932) to 1.1 x 10 (power of 4932)
                      
 real         :       2.9 x (10 power of -39) to 1.7 x (10 power of 38)

 single       :       1.5 x (10 power of -45) to 3.4 x (10 power of 38)


FreePascal:

 See Real Types Here
 See Integer Types Here


A general memory saving practise for every day programming is as follows:

Declare everything as a shortint or smallint since most numbers you will be dealing with are fairly small. When you know or see that you will be dealing with a large number, decimal number, extreme negative number, etc. then pick your best option from the chart.

However, when you restrict yourself to these small numbers without much expansion (i.e. byte) you may spend time refactoring your code too much when you decide to later expand, or when your program changes direction slightly. So the general practise is to just declare an integer or cardinal, which offers high performance for you.

When considering exporting (DLL's, DSO's), remember to check into what is safe to export. i.e. an integer in Pascal might not be the same as an "int" in another language, etc.

About
This site is about programming and other things.
_ _ _